#include "LevelInfo.h"
#include "cocos2d.h"
#include "../Support/GameSupport.h"
#include "../Data/GameData.h"

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "Cocos2dxStore.h"
using namespace soomla;
#endif

#define kPlayerLevelEnable "_level_enable_"
#define kPlayerLevelStar "_level_star_"
#define kPlayerLevelScore "_level_score_"
#define kPlayerLevelFullVersion "_level_fullversion_"
USING_NS_CC;

LevelInfo::LevelInfo()
{

}

void LevelInfo::reset()
{
	setLevelEnable(EGameMode::kMode_Easy, 1, true);
	setLevelStar(EGameMode::kMode_Easy, 1, -1);
	setLevelScore(EGameMode::kMode_Easy, 1, -1);
	setLevelEnable(EGameMode::kMode_Normal, 1, true);
	setLevelStar(EGameMode::kMode_Normal, 1, -1);
	setLevelScore(EGameMode::kMode_Normal, 1, -1);
	setLevelEnable(EGameMode::kMode_Hard, 1, true);
	setLevelStar(EGameMode::kMode_Hard, 1, -1);
	setLevelScore(EGameMode::kMode_Hard, 1, -1);

	
	for (int i = 2; i <= GameData::getInstance()->config.NumOfEasyLevel; i++)
	{

		setLevelEnable(EGameMode::kMode_Easy, i, false);
		setLevelStar(EGameMode::kMode_Easy, i, -1);
		setLevelScore(EGameMode::kMode_Easy, i, -1);
	}

	for (int i = 2; i <= GameData::getInstance()->config.NumOfNormalLevel; i++)
	{
		setLevelEnable(EGameMode::kMode_Normal, i, false);
		setLevelStar(EGameMode::kMode_Normal, i, -1);
		setLevelScore(EGameMode::kMode_Normal, i, -1);
	}

	for (int i = 2; i <= GameData::getInstance()->config.NumOfHardLevel; i++)
	{
		setLevelEnable(EGameMode::kMode_Hard, i, false);
		setLevelStar(EGameMode::kMode_Hard, i, -1);
		setLevelScore(EGameMode::kMode_Hard, i, -1);
	}
}

bool LevelInfo::getLevelEnable(EGameMode mode, int id)
{
	return UserDefault::getInstance()->getBoolForKey(String::createWithFormat("%s%s%d", GameSupport::getTextMode(mode), 
		kPlayerLevelEnable, id)->getCString());
}

void LevelInfo::setLevelEnable(EGameMode mode, int id, bool enable)
{
	UserDefault::getInstance()->setBoolForKey(String::createWithFormat("%s%s%d", GameSupport::getTextMode(mode), 
		kPlayerLevelEnable, id)->getCString(), enable);
}

void LevelInfo::setLevelStar(EGameMode mode,int id, int star)
{
    UserDefault::getInstance()->setIntegerForKey(String::createWithFormat("%s%s%d", GameSupport::getTextMode(mode), kPlayerLevelStar, id)->getCString(), star);
}

int LevelInfo::getLevelStar(EGameMode mode,int id)
{

    return UserDefault::getInstance()->getIntegerForKey(String::createWithFormat("%s%s%d", GameSupport::getTextMode(mode),kPlayerLevelStar, id)->getCString(),-1);
}

void LevelInfo::setLevelScore(EGameMode mode,int id, int score)
{
    UserDefault::getInstance()->setIntegerForKey(String::createWithFormat("%s%s%d", GameSupport::getTextMode(mode), kPlayerLevelScore, id)->getCString(), score);
}

int LevelInfo::getLevelScore(EGameMode mode,int id)
{
    
    return UserDefault::getInstance()->getIntegerForKey(String::createWithFormat("%s%s%d", GameSupport::getTextMode(mode),kPlayerLevelScore, id)->getCString(),-1);
}